package guyubao.com.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import guyubao.com.entity.dto.JDAccountDto;
import guyubao.com.mapper.JDAccountMapper;
import guyubao.com.service.JDAccountService;
import org.springframework.stereotype.Service;

@Service
public class JDAccountServiceImpl extends ServiceImpl<JDAccountMapper, JDAccountDto> implements JDAccountService {
    /***
     * 添加账号
     */
    @Override
    public String addJDAccount(String uid, String pt_pin, String nickname) {
        try {
            JDAccountDto jdAccountDto = new JDAccountDto(uid,pt_pin,nickname,nickname);
            this.save(jdAccountDto);
        }catch (Exception e){
            return "数据库添加账号失败，请联系关联人员！";
        }
        return null;
    }

    @Override
    public JDAccountDto getJDAccountByPin(String pt_pin) {
        return this.query().eq("pt_pin", pt_pin).one();
    }
    @Override
    public String updateJDAccountComment(String uid, String comment) {
        return this.update().set("comment",comment).eq("uId",uid).update() ? null:"数据库更新备注失败,请联系管理人员！";
    }

    @Override
    public String updateJDAccountAccount(String uid, String account) {
        return this.update().set("pt_pin",account).eq("uId",uid).update() ? null:"数据库更新京东账号失败,请联系管理人员！";
    }

    @Override
    public String updateJDAccountNickname(String uid, String nickname) {
        return this.update().set("nickname",nickname).eq("uId",uid).update() ? null:"数据库更新京东昵称失败,请联系管理人员！";
    }
}
